home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1990-1992 by Michael Davidson.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for any purpose and without fee is hereby
- * granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission
- * notice appear in supporting documentation.
- *
- * This software is provided "as is" without express or implied warranty.
- */
-
- unsigned char RGB8Lookup[3][256];
-
- unsigned char RGB32Bits[3] = { 8, 8, 8 };
- unsigned char RGB32Shift[3] = { 16, 8, 0 };
- unsigned long RGB32Lookup[3][256];
-
- void
- gammaLookupInit(
- long gamma,
- unsigned char *lookup
- )
- {
- extern long GammaLog10[256][2];
-
- long log_d;
- long log_v;
- int i;
- int j;
-
-
- log_d = (long)GammaLog10[255][0] * (gamma - 100);
-
- lookup[0] = 0;
- j = 0;
-
- for (i = 1; i < 255; i++)
- {
- log_v = (GammaLog10[i][0] * gamma) - log_d;
- log_v = (log_v + 50) / 100;
- while (log_v > GammaLog10[j][1] && j < 255)
- j++;
-
- lookup[i] = j;
- }
-
- lookup[255] = 255;
- }
-
- void
- vidSetGamma(
- long RedGamma,
- long GreenGamma,
- long BlueGamma
- )
- {
- register unsigned char *lookup8;
- register unsigned long *lookup32;
- register unsigned long l;
- int i, j;
- int bits, shift;
- long gamma[3];
-
- gamma[0] = RedGamma;
- gamma[1] = BlueGamma;
- gamma[2] = GreenGamma;
-
- for (i = 0; i < 3; i++)
- {
- lookup8 = RGB8Lookup[i];
- lookup32= RGB32Lookup[i];
-
- gammaLookupInit(gamma[i], lookup8);
- bits = 8 - RGB32Bits[i];
- shift = RGB32Shift[i];
-
- for (j = 0; j < 256; j++)
- {
- l = lookup8[j] >> bits;
- lookup32[j] = l << shift;
- }
- }
- }
-